<?php
/**
 * [PHPFOX_HEADER]
 */

defined('PHPFOX') or exit('NO DICE!');
/**
 * 
 * 
 * @copyright       [YOUNET_COPYRIGHT]
 * @author          YouNet Company
 * @package         YouNet_Wall
 */
?>
<!--script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script-->
{if Phpfox::isUser() && !PHPFOX_IS_AJAX && $sCustomViewType === null}
{if (Phpfox::getUserBy('profile_page_id') > 0 && defined('PHPFOX_IS_USER_PROFILE')) || (isset($aFeedCallback.disable_share) && $aFeedCallback.disable_share) || (defined('PHPFOX_IS_USER_PROFILE') && !Phpfox::getService('user.privacy')->hasAccess('' . $aUser.user_id . '', 'feed.share_on_wall'))}
{else}
{literal}
<script type="text/javascript">
// Load external libs
$Core.loadStaticFile(oParams["sJsHome"]+"module/wall/static/jscript/jquery.caret.1.02.min.js");

// Add regexIndexOf
String.prototype.regexIndexOf = function(regex, startpos) {
    var indexOf = this.substring(startpos || 0).search(regex);
    return (indexOf >= 0) ? (indexOf + (startpos || 0)) : indexOf;
}
// Regex escape
RegExp.escape = function(text) {
    return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
// DATA
var POOL = {
	// Editor supported tabs
	editorTabs:{
		'global_attachment_status':true,
		'global_attachment_photo':true,
		'global_attachment_link':true
	},
	// Alter frame controllers
	fwallPhotoFrame:'',
	//fwallVideoFrame:'',
	//fwallMusicFrame:'',
    // Friends list
    users:[],
    taggingUsers:{},
    searchUsers:function(keyword){
        var limit = 5;
        var found = new Array();
        var regKeyword = RegExp.escape(keyword);
        var regex = new RegExp(regKeyword, "i");
        // more than 2 words
        if(keyword.indexOf(' ') != -1){
            for(var i=0; i<POOL.users.length && found.length <= limit; i++){
                if(typeof(this.taggingUsers[POOL.users[i].id]) != 'undefined'){
                    continue;
                }
                if(POOL.users[i].name.regexIndexOf(regex) >= 0){
                    found.push(POOL.users[i]);
                }
            }
            return found;
        }
        // single word
        for(var i=0; i<POOL.users.length && found.length <= limit; i++){
            if(typeof(this.taggingUsers[POOL.users[i].id]) != 'undefined'){
                continue;
            }
            for(j=0; j<POOL.users[i]["words"].length; j++){
                if(POOL.users[i]["words"][j].regexIndexOf(regex)==0){
                    found.push(POOL.users[i]);
                    break;
                }
            }
        }
        return found;
    },
    // Emoticons
    emoticons:[],
    // Tagging
    tags:[],
    // Prepare pool
    prepare:function(){
        // Break down username words
        for(var i=0; i<this.users.length; i++){
            this.users[i]["words"] = new Array();
            temp = this.users[i].name.split(' ');
            for(j=0; j<temp.length; j++){
                var word = $.trim(temp[j]);
                if(word=="")
                    continue;
                this.users[i]["words"].push(word);
            }
        }
    }
};
{/literal}
{foreach from=$aFriends item="aFriend"}
POOL.users.push({l}"id":"{$aFriend.user_id}", "name":"{$aFriend.full_name|clean}", "userName":"{$aFriend.user_name|clean}", "image":"{if !empty($aFriend.user_image)}{$sCorePath}file/pic/user/{/if}{$aFriend.user_image}", "location":"{$aFriend.location}", "link":"{url link=$aFriend.user_name}"{r});
{/foreach}
{foreach from=$aEmoticons item="aEmoticon"}
POOL.emoticons.push({l}"id":"{$aEmoticon.emoticon_id}", "bbcode":"{$aEmoticon.text}", "title":"{$aEmoticon.title}", "image":"{$sCorePath}file/pic/emoticon/{$aEmoticon.package_path}/{$aEmoticon.image}"{r});
{/foreach}
POOL.fwallPhotoFrame = "{url link='wall.photo.frame'}";
//POOL.fwallVideoFrame = "{url link='wall.video.frame'}";
//POOL.fwallMusicFrame = "{url link='wall.music.frame'}";
{literal}

// Initialize
$Behavior.initWallEditor = function(){
	_Editor.currentInstance = 'user_status';
    POOL.prepare();
    _Editor.reset();
};

// Editor object
var _Editor = {
	enabled:true,
    currentInstance:"user_status",
    init:function(){
        // Setup instance
        $("._editor").focus(function(){
            _Editor.currentInstance = this.id;
        });
    	this.install();
        $Core.initActivityTabs();
        // Override feed.addComment
        $("span.activity_feed_link_form_ajax").each(function(i,e){
            if($(e).html()=='feed.addComment'){
                $(e).html('wall.addComment');
            }
        });
    },
    textToCaret:'',
    justPasted:false,
    onChanged:function(currentContent, newContent){
        // save text from begin to caret        
        var textToCaret = $("#"+_Editor.currentInstance).val().substring(0, this.currentCaret+1);
        this.textToCaret = textToCaret;
        if(textToCaret.length > 0){
        	if(textToCaret.charAt(textToCaret.length-1) == '@')
        		_Editor.onTagging();
        }
        // Tagging suggest
        if(this.isTagging){
            var atPos = textToCaret.lastIndexOf('@');
            if(atPos == -1){
                this.closeTagging();
                return;
            }
            var keyword = textToCaret.substring(atPos+1);
            this.suggestTagging(keyword);
            return;
        }
        // Paste process
        if(this.justPasted){
            this.justPasted = false;
            this.onPasted();
        }
        // Quick view
        //var linkMatches = textToCaret.match(/http:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}.*?\s+/gi);
        var linkMatches = textToCaret.match(/https*:\/\/[^\s]+?\s+$/gi);
        if(linkMatches != null && linkMatches.length > 0){}
        else{ //try again with non-http://
            linkMatches = textToCaret.match(/www\.[a-zA-Z0-9\-\._]{2,255}\.[a-zA-Z]{2,5}[^\s]*\s+$/gi);
        }
        //console.log(linkMatches);
        if(linkMatches != null && linkMatches.length > 0 && !$bIsQuickView){
            var link = $.trim(linkMatches[linkMatches.length-1]);
            var type = "text";
            $Core.openQuickView(link, type);
        }
        // Refresh tag highlight
        this.highlight();
    },
    onPasted:function(){
        this.quickViewPaste();
    },
    // quickView pasted link
    quickViewPaste:function(){
        var currentCaret = this.getCursorPos();
        var textToCaret = $("#"+_Editor.currentInstance).val().substring(0, currentCaret+1);
        //var linkMatches = textToCaret.match(/http:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}.*/gi);
        var linkMatches = textToCaret.match(/https*:\/\/[^\s]+$/gi);
        if(linkMatches != null && linkMatches.length > 0){}
        else{ //try again with non-http://
            linkMatches = textToCaret.match(/www\.[a-zA-Z0-9\-\._]{2,255}\.[a-zA-Z]{2,5}[^\s]*$/gi);
        }
        //console.log(linkMatches);
        if(linkMatches != null && linkMatches.length > 0 && !$bIsQuickView){
            var link = $.trim(linkMatches[linkMatches.length-1]);
            //console.log(link);
            var type = "text";
            $Core.openQuickView(link, type);
        }
    },
    htmlDecode:function(input){
        return $("<div/>").html(input).text();
    },
    shift_holding:false,
    ctrl_holding:false,
	keyup:function(){	
		var atPos = $(this).val().lastIndexOf('@');
        if (!_Editor.isTagging && atPos >= 0) {
        	_Editor.onTagging();
        }
	},
    keydown:function(e){
    	if(!_Editor.enabled)
    		return;
        $Core.resizeTextarea($(this));
        var code = (e.keyCode ? e.keyCode : e.which);
        // @
        if(!_Editor.isTagging && _Editor.shift_holding && code == 50){
        	// This wont work on non-ansi keyboard layout
            //_Editor.onTagging();
        }
        // Ctrl+v
        if(_Editor.ctrl_holding && code == 86){
            _Editor.justPasted = true;
        }
        _Editor.shift_holding = code == 16;
        _Editor.ctrl_holding = code == 17;
        // esc
        if(_Editor.isTagging && code == 27){
            _Editor.closeTagging();
            return false;
        }
        // arrow down
        if(_Editor.isTagging && code == 40){
            _Editor.nextTagging();
            return false;
        }
        // arrow up
        if(_Editor.isTagging && code == 38){
            _Editor.prevTagging();
            return false;
        }
        // enter or tab
        if(_Editor.isTagging && (code == 13 || code == 9)){
            _Editor.finishTagging();
            return false;
        }
    },
    currentContent:"",
    changingTrigger:function(e){
        // resize editor_wrap
        $("#editor_wrap_"+_Editor.currentInstance).css("height", $("#"+_Editor.currentInstance).height() + 10);
        var newContent = $("#"+_Editor.currentInstance).val();
        if(_Editor.currentContent != newContent){
            // Fire changed event
            var currentContent = _Editor.currentContent;
            _Editor.currentContent = newContent;
            _Editor.onChanged(currentContent, newContent);
        }
    },
    caretChangingTrigger:function(e){
        $Core.resizeTextarea($(this));
        // resize editor_wrap
        $("#editor_wrap_"+_Editor.currentInstance).css("height", $("#"+_Editor.currentInstance).height() + 10);
        var newCaret = _Editor.getCursorPos();
        if(_Editor.currentCaret != newCaret){
            var oldCaret = _Editor.currentCaret;
            _Editor.currentCaret = newCaret;
            _Editor.onCaretChanged(this, oldCaret, newCaret);
        }
    },
    reset:function(){
        $Core.closeQuickView();
        //this.init();
    },
    onCaretChanged:function(element, oldCaret, newCaret){
    },
    onTagging:function(){
        this.openTagging();
    },
    suggestList:[],
    suggestTagging:function(keyword){
        keyword = keyword || "";
        this.suggestList = POOL.searchUsers(keyword);
        var noimage = '{/literal}{img theme='noimage/profile_50.png'}{literal}';
        var html = "";
        // Populate friends list
        for(var i=0; i<this.suggestList.length; i++){
            var user = this.suggestList[i];
            if(user.image==''){
                html += '<li id="tagging_'+(i+1)+'" onmouseover="_Editor.taggingHover = true; _Editor.suggestItemHover('+(i+1)+');" onmouseout="_Editor.taggingHover = false;" onclick="_Editor.finishTagging();">'+noimage+'<div class="fullname">'+user.name+'</div><div class="location">'+user.location+'</div></li>';
            }
            else{
                user.image = user.image.replace("%s", "_50_square");
                html += '<li id="tagging_'+(i+1)+'" onmouseover="_Editor.taggingHover = true; _Editor.suggestItemHover('+(i+1)+');" onmouseout="_Editor.taggingHover = false;" onclick="_Editor.finishTagging();"><img src="'+user.image+'" alt="image"/><div class="fullname">'+user.name+'</div><div class="location">'+user.location+'</div></li>';
            }
        }
        $("#friend_suggest_"+_Editor.currentInstance).html(html);
        this.activeTagging(1);
    },
    suggestItemHover:function(index){
        this.currentTagIndex = index;
        this.activeTagging(index);
    },
    isTagging:false,
    openTagging:function(){
        this.isTagging = true;
        this.suggestTagging();
        $("#friends_tagging_"+_Editor.currentInstance).show();
        this.activeTagging(1);
        $("#friends_tagging_"+_Editor.currentInstance+" input").focus();
    },
    currentTagIndex:0,
    taggingHover:false,
    activeTagging:function(index){
        this.currentTagIndex = index;
        $("#friend_suggest_"+_Editor.currentInstance+" li").removeClass("active");
        $("#friend_suggest_"+_Editor.currentInstance+" li#tagging_"+index).addClass("active");
    },
    closeTagging:function(){
        this.isTagging = false;
        $(".friends_tagging").hide();
    },
    nextTagging:function(){
        if(this.currentTagIndex==this.suggestList.length){
            return;
        }
        this.currentTagIndex++;
        this.activeTagging(this.currentTagIndex);
    },
    prevTagging:function(){
        if(this.currentTagIndex==1){
            return;
        }
        this.currentTagIndex--;
        this.activeTagging(this.currentTagIndex);
    },
    finishTagging:function(){
        // Get selected tag
        var selectedUser = this.suggestList[this.currentTagIndex-1];
        var userid = selectedUser.id;
        var name = this.htmlDecode(selectedUser.name);
        var userName = this.htmlDecode(selectedUser.userName);
        POOL.taggingUsers[userid] = {"name" : name, "userName" : userName};
        // Insert tag
        var atPos = this.textToCaret.lastIndexOf('@');
        if(atPos == -1){
            this.closeTagging();
            return;
        }
        var start = $("#"+_Editor.currentInstance).val().substring(0, atPos);
        var end = $("#"+_Editor.currentInstance).val().substring(this.textToCaret.length);
        var newText = start + name + end;
        $("#"+_Editor.currentInstance).val(newText);
        var newCaret = atPos + name.length;
        $("#"+_Editor.currentInstance).caret({start:newCaret,end:newCaret});
        // Highlight tag
        this.highlight();
        this.closeTagging();
    },
    highlight:function(){
        var available = {};
        var html = this.htmlEntities($("#"+_Editor.currentInstance).val());
        for(var userid in POOL.taggingUsers){
            var tag = POOL.taggingUsers[userid];
            if(tag==null){
                continue;
            }
            var taggingName = tag["name"];
            var tagStart = html.indexOf(taggingName);
            if(tagStart == -1){
                POOL.taggingUsers[userid] = null;
                continue;
            }
            html = html.substring(0, tagStart) + '<b>' + taggingName + '</b>' + html.substring(tagStart + taggingName.length);
            available[userid] = tag;
        }
        POOL.taggingUsers = available;
        $(".editor_highlight").html(html.replace(/\n/g, '<br/>')); // Highlight for all editors
    },
    htmlEntities:function(str){
        return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
    },
    getCursorPos:function(){
        return $("#"+_Editor.currentInstance).caret().start;
    },
    // Current caret
    currentCaret:0,
    emoticon:function(param){
        $(".toolbar_icon ins > div > div").hide();
        // insert emoticon image
        if(typeof(param)=="number"){
            $("#"+_Editor.currentInstance).focus();
            var bbcode = POOL.emoticons[param]["bbcode"];
            var start = $("#"+_Editor.currentInstance).val().substring(0, this.currentCaret);
            var end = $("#"+_Editor.currentInstance).val().substring(this.currentCaret);
            var newText = start + bbcode + end;
            $("#"+_Editor.currentInstance).val(newText);
            var newCaret = this.currentCaret + bbcode.length;
            $("#"+_Editor.currentInstance).caret({start:newCaret,end:newCaret});
            this.changingTrigger();
            return;
        }
        // show/hide emoticons list
        if(typeof(param)=="boolean" && param==false){
            $(".toolbar_emoticons").hide();
            return;
        }
        if($("#toolbar_emoticons_"+_Editor.currentInstance).html()==""){
            var html = '<table cellpadding="0" style="border-spacing:1px; border-collapse:inherit;">';
            for(var i=0; i<POOL.emoticons.length;){
                html += '<tr>';
                for(j=0; j<4 && i<POOL.emoticons.length; j++, i++){
                    html += '<td onclick="_Editor.emoticon('+i+');"><a class="emoticon_item" href="javascript:void(0)" style="background:url('+POOL.emoticons[i].image+') center center no-repeat;"></a></td>';
                    html += '<td onclick="_Editor.emoticon('+i+');">&nbsp;'+POOL.emoticons[i].title+'&nbsp;&nbsp;</td>';
                }
                html += '</tr>';
            }
            html += '</table>';
            $("#toolbar_emoticons_"+_Editor.currentInstance).html(html);
        }
        // Align and show
        $("#toolbar_emoticons_container_"+_Editor.currentInstance).css("margin-left", -1 * $("#toolbar_emoticons_"+_Editor.currentInstance).width() + 18);
        $("#toolbar_emoticons_"+_Editor.currentInstance).show();
    },
    install:function(){
    	_Editor.enabled = true;
    	$(".toolbar_icon.emoticon").show();
    	$("._editor").css('background', 'transparent');
        // Resize editor (1col/2cols mode)
        var _w = $("#activity_feed_form_holder").width() - 28;
        $("#editor_wrap_"+_Editor.currentInstance).css("width", _w);
        $("#"+_Editor.currentInstance).css("width", _w - 10);
    	//debug($("#"+_Editor.currentInstance));
        $(".editor_wrap").css('background', '#ffffff');
        // Resize wrapper
        $("#editor_wrap_"+_Editor.currentInstance).css("height", $("#"+_Editor.currentInstance).height() + 10);
        $(".editor_highlight").html("");
        // Events
        $("._editor").unbind("keydown");
		$("._editor").unbind("keyup");
        $("._editor").keydown(_Editor.keydown);
		$("._editor").keydown(_Editor.keyup);
        $("._editor").bind("mouseover mouseout keyup", _Editor.changingTrigger);
        $("._editor").bind("click keyup", _Editor.caretChangingTrigger);
        $("._editor").blur(function(){
            if(_Editor.taggingHover){
                return;
            }
            _Editor.closeTagging();
        });
    },
    uninstall:function(){
    	_Editor.enabled = false;
    	$(".toolbar_icon.emoticon").hide();
        $("._editor").css('background', '#ffffff');
        $("._editor").css("width", '98%');
        $(".editor_wrap").css("height", '30px');
        $(".editor_wrap").css("width", 'auto');
        $(".editor_wrap").css("background", 'none');
        $(".editor_highlight").html("");
        // Events
        $("._editor").unbind("mouseover mouseout click blur");
        _Editor.closeTagging();
    }
};
// wall
var reload_wall = 1;
$Core.reloadWall = function(){
    setTimeout("$.ajaxCall('wall.reloadActivityFeed', 'reload-ids=' + $Core.getCurrentFeedIds() + '&viewId=' + $('#feed_type_id').val(), 'GET');", 2000);
};
$Core.loadMoreFeeds = function() { reload_wall = 0;
	var viewId = $("#feed_type_id").val();
	$('#js_feed_content').html('<div id="feed_filtering_animation">{/literal}{img theme='ajax/add.gif' class='v_middle'}{literal}</div>');
    setTimeout("doFilter('"+viewId+"')", 100);
	return false;
	/*
	var viewId = $("#feed_type_id").val();
    $.ajaxCall('wall.appendMore', 'ids=' + sMoreFeedIds + '&viewId=' + viewId, 'GET');
    return false;
	*/
}
$Core.getCurrentFeedIds = function()
{
	var sMoreFeedIds = '';
	$('.js_parent_feed_entry').each(function(){
		sMoreFeedIds += $(this).attr('id').replace('js_item_feed_', '').replace('row_hidden_feed_', '') + ',';				
	});
	return sMoreFeedIds;
}
$Core.initActivityTabs = function(){
    $(".activity_feed_form_attach > li > a").click(function(){
    	// Switch editors
        if(this.rel == 'global_attachment_status'){
            _Editor.currentInstance = 'user_status';
        }
        else{
            _Editor.currentInstance = 'status_info';
        }
        // Check if the editor support this tab
    	if(typeof(POOL.editorTabs[this.rel])=='undefined')
    	{
    		_Editor.uninstall();
    	}
    	else
    	{
    		_Editor.install();
    	}
        $('.activity_feed_form_button_status_info > textarea').val($(this).find('.activity_feed_extra_info:first').html());
        // Resize wrapper
        $("#editor_wrap_"+_Editor.currentInstance).css("height", $("#"+_Editor.currentInstance).height() + 10);
    });
    $('a[rel="global_attachment_photo"] .activity_feed_link_form').html(POOL.fwallPhotoFrame);
    //$('a[rel="global_attachment_video"] .activity_feed_link_form').html(POOL.fwallVideoFrame);
    $('#activity_feed_link_form_ajax_link').html('wall.addLinkViaStatusUpdate');
    //$('#activity_feed_link_form_ajax_blog').html('wall.addBlogViaStatusUpdate');
    //$('a[rel="global_attachment_music"] .activity_feed_link_form').html(POOL.fwallMusicFrame);
    
};
var feed_filter = function(type, value, element){
    switch(type){
        case "type":
            $("#feed_type_id").val(value);
            $("#feed_type_id_label").html(element.innerHTML);
        break;
        case "limit":
            $("#feed_limit").val(value);
            $("#feed_limit_label").html(element.innerHTML);
        break;
    }
    var viewId = $("#feed_type_id").val();
    //var limit = $("#feed_limit").val();
    $('#js_feed_content').html('<div id="feed_filtering_animation">{/literal}{img theme='ajax/add.gif' class='v_middle'}{literal}</div>');
    setTimeout("doFilter('"+viewId+"')", 100);
}
var doFilter = function(viewId) {
	$('#activity_feed_updates_link_holder').hide();
	$iReloadIteration = 0;	
    $.ajaxCall('wall.filterFeed', 'viewId=' + viewId + '&userId=' + $('#userId').val(), 'GET');
};
var feed_filter_success = function(){
    $("#feed_filtering_animation").remove();
	reload_wall = 1;
}
var activity_feed_submit = function(input){
	if($(input).hasClass('button_not_active'))
	{
		return false;
	}
	if($('a[rel="global_attachment_poll"]').hasClass('active'))
	{
		return true;
	}
	/*
    if(!$("#global_attachment_status").is(":visible")){
        return true;
    }
    */
    
    // Reset ajax target if quickview is visisble
    if($('#quickview_preview').is(":visible")){
        $("#user_status_link_form_ajax").html('wall.addViaStatusUpdate');
    }
    if($('ul.activity_feed_form_attach > li > a[rel="global_attachment_status"]').hasClass('active'))
    {
    	$("#js_global_attach_value").val($("#quickview_url").val());
    }
    else
    {
    	$("#quickview_url").val($("#js_global_attach_value").val());
    }
    var json = new Array();
    for(var userid in POOL.taggingUsers){
        json.push('"'+userid+'":{"name":"'+POOL.taggingUsers[userid]["name"]+'","userName":"'+POOL.taggingUsers[userid]["userName"]+'"}');
    }
    json = '{' + json.join(',') + '}';
    $("#tagging_users").val(json);
	
    $Behavior.activityFeedProcess();//important
    if($bIsQuickView){
        $Core.closeQuickView();
        //$(".activity_feed_form_button_status_info > textarea").val($("#user_status").val());
    }
    if(!$("#global_attachment_status").is(":visible") && !$('a[rel="global_attachment_link"]').hasClass('active') && !$('a[rel="global_attachment_blog"]').hasClass('active')){
    	document.getElementById("js_activity_feed_form").submit();
    }
}
// Quickview
var $bIsQuickView = false;
$Core.openQuickView = function(link, type)
{
    if($('#quickview_preview').is(":visible")){
        return;
    }
    $("#quickview_url").val(link);    
    $("#quickview_type").val(type);
    $(".activity_feed_form_share_process").show();
    $bIsQuickView = true;
    
    $Core.ajax("link.preview", 
    {
        params: 
        {
            'no_page_update': '1',
            value: link
        },
        success: function($sOutput)
        {
            if (substr($sOutput, 0, 1) == '{')
            {
                $bIsQuickView = false;
                var $oOutput = $.parseJSON($sOutput);
                $('#quickview_error').html('<div class="error_message">' + $oOutput['error'] + '</div>');
                $('#quickview_error').show();
            }
            else
            {
                $('#quickview_preview').html($sOutput);
                $('#quickview_preview').show();
                $('#quickview_preview_cancel').show();        
                // Fix the attachment editor (phpfox)
                $(".js_text_attachment_edit_link").click(function(){
                    $(this).parent().find(".js_text_attachment_edit_value").css("height","auto");
                     $(this).parent().find(".js_text_attachment_edit_value").caret({'start':0,'end':0});
                });
            }
            $(".activity_feed_form_share_process").hide();
            _Editor.init();
            $("#editor_wrap_"+_Editor.currentInstance).css("height", $("#"+_Editor.currentInstance).height() + 10);
        }
    });
};
$Core.closeQuickView = function()
{
    $('#quickview_preview').hide();
    $('#quickview_error').hide();
    $('#quickview_preview_cancel').hide();
    $("#quickview_type").val('');
    $bIsQuickView = false;
    $("#user_status_link_form_ajax").html('wall.updateStatus');
    _Editor.init();
};
$Core.forceLoadOnFeed = function()
{
    if ($iReloadIteration >= 2)
        return;
    
    $iReloadIteration++;
    $('#feed_view_more_loader').show();
    $('.global_view_more').hide();
    setTimeout("var viewId = $('#feed_type_id').val(); $.ajaxCall('wall.viewMore', $('#js_feed_pass_info').html().replace('&amp;', '&') + '&viewId=' + viewId, 'GET');", 1000);
}
</script>
<style type="text/css">
#js_block_border_wall_display .user_profile_link_span a, .item_feed_entry .user_profile_link_span a {
    font-weight: bold;
}
.feed_hide_link, .feed_show_link {
    display: none;
    position: absolute;
    right: 20px;
    top: 4px;
}
.action_hide, .action_hide:hover {
    {/literal}
    background: url("{$sImageWall}/action_hide.png") no-repeat scroll 0 0 transparent;
    {literal}
    display: block;
    height: 16px;
    overflow: hidden;
    position: relative;
    text-indent: -1000px;
    width: 16px;
}
.action_show, .action_show:hover {
    {/literal}
    background: url("{$sImageWall}/action_show.png") no-repeat scroll 0 0 transparent;
    {literal}
    display: block;
    height: 16px;
    overflow: hidden;
    position: relative;
    text-indent: -1000px;
    width: 16px;
}
.action_hide:hover, .action_show:hover {
    background-color: #333333;
}
.row_feed_hidden{
    min-height: 32px;
    position: relative;
}
.row_feed_hidden .activity_feed_content{
    line-height: 20px;
}
#js_block_border_wall_display .content{
    padding-top: 0px;
}
#js_block_border_wall_display > .title{
    display: none;
}
div.title.header_bar_menu{
    background: none; 
    padding-left: 0px;
    padding-top: 0px;
}
#js_block_border_wall_display .header_filter_holder{
    top:0px;
}
#js_block_border_wall_display > .content > .title{
    margin-bottom: 8px;
}
#content .block .title .header_filter_holder {
    color: inherit;
    font-size: 12px;
    font-weight: normal;
}
#feed_filtering_animation{
    text-align: center;
    padding: 5px;
}
.toolbar{
    padding:4px;
    width:98%;
    display:none;
    text-align:right;
}
.toolbar_icon{
    background-color:transparent;
    background-position: center center;
    background-repeat: no-repeat;
    display:inline-block;
    padding:3px;
    border:1px #CCC solid;
    width:16px;
    height:16px;
    float:right;
}
.toolbar_icon a ins{
    text-decoration:none;
}
.toolbar_icon:hover{
    background-color:#FFF;
    border:1px #999 solid;
}
.toolbar_emoticons{
    position:relative;
    left:-4px;
    top:-4px;
    z-index: 100;
    padding:2px;
    border:1px #CCC solid;
    background-color:#FFF;
    display:none;
}
.toolbar_emoticons .emoticon_item{
    width:20px;
    height:20px;
    display:block;
    border:1px #FFF solid;
}
.toolbar_emoticons .emoticon_item:hover{
    border:1px #CCC solid;
}
.toolbar_emoticons td{
    vertical-align:middle;
}
.toolbar_icon.emoticon{
    {/literal}
    background: url("{$sImageWall}/emoticon_smile.png") no-repeat scroll center center transparent;
    {literal}
}
/* friends tagging */
.friends_tagging_holder{
    position:absolute;
}
.friends_tagging{
     background:#FFF;
     border:1px #CCC solid;
     position:relative;
     left:0px;
     top:0px;
     display: none;
     z-index: 100;
     margin-left:-1px;
}
ul.friend_suggest{
    display:block;
    margin:0;
    padding:0;
    list-style:none;
}
ul.friend_suggest li{
    display:block;
    width:510px;
    padding:4px;
    border-top:1px #CCC solid;
    height:32px;
    cursor:pointer;
}
ul.friend_suggest li > img:first-child{
    max-width:32px;
    max-height:32px;
    float:left;
}
ul.friend_suggest li .fullname{
    padding:0px 0px 3px 38px;
    font-weight:bold;
}
ul.friend_suggest li.active{
    background:#3B5998;
}
ul.friend_suggest li.active .fullname{
    color:#fff;
}
ul.friend_suggest li.active .location{
    color:#b9c7e4;
}
ul.friend_suggest li .location{
    padding-left:38px;
}
ul.friend_suggest li:first-child{
    border-top:none;
}
.activity_feed_content_status{
    word-wrap: break-word;
}
._editor{
    position:absolute;
    z-index:10;
    left:-1px;
    top:-1px;
}
.activity_feed_form textarea._editor{
    background:none;
}
.editor_highlight{
    background:none;
    position:absolute;
    z-index:1;
    left:0px;
    top:0px;
    padding:5px;
    font-family:monospace;
    font-size:13px;
    font-weight:400;
    font-style:normal;
    color:#fff;
    line-height:16px;
}
.editor_highlight b{
    background:#d9f4ff;
    font-weight:400;
    color:#d9f4ff;
}   
.editor_wrap{
    background:#fff;
    position:relative;
    height:30px;
    width:480px;
}
#js_is_user_profile #content .block .title{
    background:#fff;
}
</style>
{/literal}
<input type="hidden" id="userId" value="{$iUserId}"/>
<div class="title header_bar_menu">
    <div class="js_edit_header_bar js_edit_header_hover" style="display:none;">
        {if Phpfox::getService('theme')->isInDnDMode() }
            <a href="#" onclick="if (confirm('{phrase var='core.are_you_sure' phpfox_squote=true}')){left_curly}
            $(this).parents('.block:first').remove(); $.ajaxCall('core.removeBlockDnD', 'sController=' + oParams['sController'] 
            + '&amp;block_id={if isset($sDeleteBlock)}{$sDeleteBlock}{else} {$sBlockBorderJsId}{/if}');{right_curly} return false;"title="{phrase var='core.remove_this_block'}">
                {img theme='misc/application_delete.png' alt='' class='v_middle'}
            </a>
        {else}                
            <a href="#" onclick="if (confirm('{phrase var='core.are_you_sure' phpfox_squote=true}')) {left_curly} $(this).parents('.block:first').remove();
            $.ajaxCall('core.hideBlock', 'sController=' + oParams['sController'] + '&amp;type_id={if isset($sDeleteBlock)}{$sDeleteBlock}{else} {$sBlockBorderJsId}{/if}&amp;block_id=' + $(this).parents('.block:first').attr('id')); {right_curly} return false;" title="{phrase var='core.remove_this_block'}">
                {img theme='misc/application_delete.png' alt='' class='v_middle'}
            </a>                
        {/if}
    </div>
    <span>{phrase var='feed.activity_feed'}</span>
   
    <!--FILTER-->
    <div class="header_filter_holder">                                
        <div class="header_bar_float">                            
            <div class="header_bar_drop_holder">
                <input id="feed_type_id" value="all" type="hidden" />
                <ul class="header_bar_drop">
                    <li><span>{phrase var='wall.filter'}:</span></li>
                    <li><a id="feed_type_id_label" class="header_bar_drop" href="#">{phrase var='wall.all_feeds'}</a></li>
                </ul>
                <div class="clear"></div>
                <div class="action_drop_holder" style="display: none;">
                    <ul class="action_drop">
                    {foreach from=$aFeedTypes key="sTypeId" item="sType"}
                        <li><a class="ajax_link" href="javascript:void(0)" onclick="feed_filter('type', '{$sTypeId}', this);">{$sType}</a></li>
                    {/foreach}
                    </ul>
                </div>
            </div>
        </div>
        <div class="clear"></div>
    </div>
    <!--END-FILTER-->
</div>
	{plugin call='ycus.show_info_pet'}
	
<div class="activity_feed_form_share">
	<div class="activity_feed_form_share_process">{img theme='ajax/add.gif' class='v_middle'}</div>
	<ul class="activity_feed_form_attach">
		{if !Phpfox::isMobile()}
		<li class="share">{phrase var='feed.share'}:</li>
		{/if}
		{if isset($aFeedCallback.module)}
		<li><a href="#" style="background:url('{img theme='misc/comment_add.png' return_url=true}') no-repeat center left;" rel="global_attachment_status" class="active"><div>{phrase var='feed.post'}<span class="activity_feed_link_form_ajax">{$aFeedCallback.ajax_request}</span></div><div class="drop"></div></a></li>
		{elseif !isset($bFeedIsParentItem) && (!defined('PHPFOX_IS_USER_PROFILE') || (defined('PHPFOX_IS_USER_PROFILE') && isset($aUser.user_id) && $aUser.user_id == Phpfox::getUserId()))}
		<li><a href="#" style="background:url('{img theme='misc/application_add.png' return_url=true}') no-repeat center left;" rel="global_attachment_status" class="active"><div>{phrase var='feed.status'}<span class="activity_feed_link_form_ajax" id="user_status_link_form_ajax">wall.updateStatus</span></div><div class="drop"></div></a></li>
		{else}
		<li><a href="#" style="background:url('{img theme='misc/comment_add.png' return_url=true}') no-repeat center left;" rel="global_attachment_status" class="active"><div>{phrase var='feed.post'}<span class="activity_feed_link_form_ajax">feed.addComment</span></div><div class="drop"></div></a></li>
		{/if}
		
		{foreach from=$aFeedStatusLinks item=aFeedStatusLink}
		{if isset($aFeedCallback.module) && $aFeedStatusLink.no_profile}
		{else}
		{if ($aFeedStatusLink.no_profile && !isset($bFeedIsParentItem) && (!defined('PHPFOX_IS_USER_PROFILE') || (defined('PHPFOX_IS_USER_PROFILE') && isset($aUser.user_id) && $aUser.user_id == Phpfox::getUserId()))) || !$aFeedStatusLink.no_profile}
		<li>
			<a href="#" style="background:url('{img theme='feed/'$aFeedStatusLink.icon'' return_url=true}') no-repeat center left;" rel="global_attachment_{$aFeedStatusLink.module_id}"{if $aFeedStatusLink.no_input} class="no_text_input"{/if}>
				<div>
					{$aFeedStatusLink.title|convert}
					{if $aFeedStatusLink.is_frame}
					<span class="activity_feed_link_form">{url link=''$aFeedStatusLink.module_id'.frame'}</span>
					{else}
					<span id="activity_feed_link_form_ajax_{$aFeedStatusLink.module_id}" class="activity_feed_link_form_ajax">{$aFeedStatusLink.module_id}.{$aFeedStatusLink.ajax_request}</span>
					{/if}
					<span class="activity_feed_extra_info">{$aFeedStatusLink.description|convert}</span>
				</div>
				<div class="drop"></div>
			</a>
		</li>
		{/if}
		{/if}
		{/foreach}		
	</ul>
	<div class="clear"></div>
</div>	

<div class="activity_feed_form">
	<form method="post" action="#" id="js_activity_feed_form" enctype="multipart/form-data">
    <input id="tagging_users" type="hidden" name="val[tagging]" value=""/>
	{if isset($aFeedCallback.module)}
		<div><input type="hidden" name="val[callback_item_id]" value="{$aFeedCallback.item_id}" /></div>
		<div><input type="hidden" name="val[callback_module]" value="{$aFeedCallback.module}" /></div>
		<div><input type="hidden" name="val[parent_user_id]" value="{$aFeedCallback.item_id}" /></div>
	{/if}
	{if isset($bFeedIsParentItem)}
		<div><input type="hidden" name="val[parent_table_change]" value="{$sFeedIsParentItemModule}" /></div>
	{/if}
		{if defined('PHPFOX_IS_USER_PROFILE') && isset($aUser.user_id) && $aUser.user_id != Phpfox::getUserId()}
		<div><input type="hidden" name="val[parent_user_id]" value="{$aUser.user_id}" /></div>
		{/if}	
		<div id="activity_feed_form_holder" class="activity_feed_form_holder">		
		
			<div id="activity_feed_upload_error" style="display:none;"><div class="error_message" id="activity_feed_upload_error_message"></div></div>
			
			<div class="global_attachment_holder_section" id="global_attachment_status" style="display:block;">
                <!--QUICK-VIEW-->
                <input id="quickview_url" type="hidden" name="val[link][url]" value=""/>
                <input id="quickview_type" type="hidden" name="val[link][type]" value=""/>
                <div class="js_preview_content_holder" id="quickview_error"></div>
                <div class="js_preview_content_holder" id="quickview_preview"></div>
                <div id="quickview_preview_cancel" class="p_4 t_right" style="display:none;">
                    <a href="#" onclick="$Core.closeQuickView();">{phrase var='link.cancel'}</a>
                </div>
                <!--/QUICK-VIEW-->
				<div id="global_attachment_status_value" style="display:none;">{if isset($aFeedCallback.module) || defined('PHPFOX_IS_USER_PROFILE')}{phrase var='feed.write_something'}{else}{phrase var='feed.what_s_on_your_mind'}{/if}</div>
                <div>
                    <a class="toolbar_icon emoticon" href="javascript:void(0)" onmouseover="_Editor.emoticon(true);" onmouseout="_Editor.emoticon(false);">
                        <ins>
                            <div style="position:absolute;" id="toolbar_emoticons_container_user_status" class="toolbar_emoticons_container">
                                <div id="toolbar_emoticons_user_status" class="toolbar_emoticons"></div>
                            </div>
                        </ins>
                    </a>
                </div>
                <div id="editor_wrap_user_status" class="editor_wrap">
                    <div id="editor_highlight_user_status" class="editor_highlight"></div>
                    <textarea id="user_status" class="_editor" cols="60" rows="8" name="val[user_status]">{if isset($aFeedCallback.module) || defined('PHPFOX_IS_USER_PROFILE')}{phrase var='feed.write_something'}{else}{phrase var='feed.what_s_on_your_mind'}{/if}</textarea>
                </div>
			</div>
			
			{foreach from=$aFeedStatusLinks item=aFeedStatusLink}
			{if !empty($aFeedStatusLink.module_block)}
			{module name=$aFeedStatusLink.module_block}			
			{/if}
			{/foreach}		
			{if Phpfox::isModule('egift')}
			{module name='egift.display'}
			{/if}
		</div>
        <div class="friends_tagging_holder">
            <!--FRIENDS-->
            <div id="friends_tagging_user_status" class="friends_tagging">
                <ul id="friend_suggest_user_status" class="friend_suggest"></ul>
            </div>
            <!--/FRIENDS-->
        </div>
		<div class="activity_feed_form_button">
			<div class="activity_feed_form_button_status_info">
                <div>
                    <a class="toolbar_icon emoticon" href="javascript:void(0)" onmouseover="_Editor.emoticon(true);" onmouseout="_Editor.emoticon(false);">
                        <ins>
                            <div style="position:absolute;" id="toolbar_emoticons_container_status_info" class="toolbar_emoticons_container">
                                <div id="toolbar_emoticons_status_info" class="toolbar_emoticons"></div>
                            </div>
                        </ins>
                    </a>
                </div>
                <div id="editor_wrap_status_info" class="editor_wrap">
                    <div id="editor_highlight_status_info" class="editor_highlight"></div>
                    <textarea id="status_info" class="_editor" cols="60" rows="8" name="val[status_info]"></textarea>
                </div>
                <div class="friends_tagging_holder">
                    <!--FRIENDS-->
                    <div id="friends_tagging_status_info" class="friends_tagging">
                        <ul id="friend_suggest_status_info" class="friend_suggest"></ul>
                    </div>
                    <!--/FRIENDS-->
                </div>
			</div>
			<div class="activity_feed_form_button_position">
			
				{if defined('PHPFOX_IS_PAGES_VIEW') && $aPage.is_admin && $aPage.page_id != Phpfox::getUserBy('profile_page_id')}
				<div class="activity_feed_pages_post_as_page">
					{phrase var='feed.post_as'}: 
					<select name="custom_pages_post_as_page">
						<option value="{$aPage.page_id}">{$aPage.full_name|clean|shorten:20:'...'}</option>
						<option value="0">{$sGlobalUserFullName}</option>
					</select>
				</div>
				{else}
				{if Phpfox::isModule('share') && !defined('PHPFOX_IS_USER_PROFILE') && (Phpfox::getParam('share.share_on_facebook') || Phpfox::getParam('share.share_on_twitter'))}
				<div id="activity_feed_share_this_one">					
					<a href="#" id="activity_feed_share_this_one_link">{phrase var='feed.share_this_on'}</a>
					<div class="feed_share_on_holder">						
						{if Phpfox::getParam('share.share_on_facebook')}
						<div class="feed_share_on_item"><a href="#" onclick="$(this).toggleClass('active'); $.ajaxCall('share.connect', 'connect-id=facebook', 'GET'); return false;">{img theme='layout/facebook.png' class='v_middle'} {phrase var='feed.facebook'}</a></div>
						{/if}
						{if Phpfox::getParam('share.share_on_twitter')}
						<div class="feed_share_on_item"><a href="#" onclick="$(this).toggleClass('active'); $.ajaxCall('share.connect', 'connect-id=twitter', 'GET'); return false;">{img theme='layout/twitter.png' class='v_middle'} {phrase var='feed.twitter'}</a></div>
						{/if}
						<div><input type="hidden" name="val[connection][facebook]" value="0" id="js_share_connection_facebook" class="js_share_connection" /></div>
						<div><input type="hidden" name="val[connection][twitter]" value="0" id="js_share_connection_twitter" class="js_share_connection" /></div>
					</div>					
				</div>
				{/if}
				{/if}
				
				<div class="activity_feed_form_button_position_button">
					<input type="submit" value="{phrase var='feed.share'}" class="button" onclick="return activity_feed_submit(this);" />
				</div>				
				{if isset($aFeedCallback.module)}
				{else}
				{if !isset($bFeedIsParentItem) && (!defined('PHPFOX_IS_USER_PROFILE') || (defined('PHPFOX_IS_USER_PROFILE') && isset($aUser.user_id) && $aUser.user_id == Phpfox::getUserId()))}
				{module name='privacy.form' privacy_name='privacy' privacy_type='mini'}
				{/if}
				{/if}
				<div class="clear"></div>
			</div>
		</div>			
	</form>
	<div class="activity_feed_form_iframe"></div>
</div>
{/if}
{/if}

{if Phpfox::getParam('feed.refresh_activity_feed') > 0 && Phpfox::getLib('module')->getFullControllerName() == 'core.index-member'}
<div id="activity_feed_updates_link_holder">
    <a href="#" id="activity_feed_updates_link_single" class="activity_feed_updates_link" onclick="return $Core.loadMoreFeeds();">{phrase var='feed.1_new_update'}</a>
    <a href="#" id="activity_feed_updates_link_plural" class="activity_feed_updates_link" onclick="return $Core.loadMoreFeeds();">{phrase var='feed.span_id_js_new_update_view_span_new_updates'}</a>
	</div>
{/if}

{if Phpfox::isModule('captcha') && Phpfox::getUserParam('captcha.captcha_on_comment')}
{module name='captcha.form' sType='comment' captcha_popup=true}
{/if}

<div id="feed"><a name="feed"></a></div>
<div id="js_feed_content">
	{if $sCustomViewType !== null}
	<h2>{$sCustomViewType}</h2>
	{/if}
	<div id="js_new_feed_comment"></div>
	<div id="js_new_feed_update"></div>
	{foreach from=$aFeeds name=iFeed item=aFeed}
	
	{if isset($aFeed.feed_mini) && !isset($bHasRecentShow)}
	{if $bHasRecentShow = true}{/if}
	<div class="activity_recent_holder">
	<div class="activity_recent_title">
		{phrase var='feed.recent_activity'}
	</div>
	{/if}
	{if !isset($aFeed.feed_mini) && isset($bHasRecentShow)}
	</div>
	{unset var=$bHasRecentShow}
	{/if}
	
	<div class="js_feed_view_more_entry_holder">
		{template file='wall.block.entry'}
		{if isset($aFeed.more_feed_rows) && is_array($aFeed.more_feed_rows) && count($aFeed.more_feed_rows)}
		{foreach from=$aFeed.more_feed_rows item=aFeed}
		{if $bChildFeed = true}{/if}
		<div class="js_feed_view_more_entry" style="display:none;">
			{template file='wall.block.entry'}
		</div>
		{/foreach}
		{unset var=$bChildFeed}
		{/if}
	</div>
	{/foreach}
	
	{if isset($bHasRecentShow)}
	</div>
	{/if}	
	{if $sCustomViewType === null}
	{if defined('PHPFOX_IN_DESIGN_MODE')}
	
	{else}
	{if count($aFeeds)}
	<div id="feed_view_more">
		<div id="js_feed_pass_info" style="display:none;">page={$iFeedNextPage}{if defined('PHPFOX_IS_USER_PROFILE') && isset($aUser.user_id)}&profile_user_id={$aUser.user_id}{/if}{if isset($aFeedCallback.module)}&callback_module_id={$aFeedCallback.module}&callback_item_id={$aFeedCallback.item_id}{/if}</div>
		<div id="feed_view_more_loader">{img theme='ajax/add.gif'}</div>
		<a href="{if Phpfox::getLib('module')->getFullControllerName() == 'core.index-visitor'}{url link='core.index-visitor' page=$iFeedNextPage}{else}{url link='current' page=$iFeedNextPage}{/if}" onclick="$(this).hide(); $('#feed_view_more_loader').show(); var viewId = $('#feed_type_id').val(); $.ajaxCall('wall.viewMore', 'page={$iFeedNextPage}&viewId='+viewId+'{if defined('PHPFOX_IS_USER_PROFILE') && isset($aUser.user_id)}&profile_user_id={$aUser.user_id}{/if}{if isset($aFeedCallback.module)}&callback_module_id={$aFeedCallback.module}&callback_item_id={$aFeedCallback.item_id}{/if}', 'GET'); return false;" class="global_view_more no_ajax_link">{phrase var='feed.view_more'}</a>
	</div>
	{else}
	<br />
	<div class="message js_no_feed_to_show">{phrase var='feed.there_are_no_new_feeds_to_view_at_this_time'}</div>
	{/if}
	{/if}
	{/if}
{if !PHPFOX_IS_AJAX || (PHPFOX_IS_AJAX && count($aFeedVals))}
</div>
{/if}
{if Phpfox::getParam('feed.refresh_activity_feed') > 0 && Phpfox::getLib('module')->getFullControllerName() == 'core.index-member'}
<script type="text/javascript">
$Behavior.initActivityTabs = $Core.initActivityTabs;
$Behavior.reloadWall = $Core.reloadWall;
</script>
{/if} 
